package com.biomed.facon.ftc.demo

import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.biomed.facon.ftc.sdk.DetectionManager
import com.biomed.facon.ftc.sdk.ITesterInfo
import java.util.Locale


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        DetectionManager.setUserTag("18812345678")
//        DetectionManager.enableSkipAnimation(true)
        findViewById<View>(R.id.openDeteBtn).setOnClickListener {
            val isSuccess = DetectionManager.startDetect(this,ITesterInfo
                .Builder()
                .iTesterId("7878121")  //三方业务系统的被测人用户id
                .iTesterBirthdayDisplay(true)
                .iTesterAreaDisplay(true)
                .iTesterPhoneDisplay(true)
                .iTesterNameDisplay(true)
                .iTesterHeightDisplay(true)
                .iTesterWeightDisplay(true)
                .build()
            ){
                Toast.makeText(this@MainActivity,it,Toast.LENGTH_SHORT).show()
            }
            if(!isSuccess){
                Toast.makeText(this@MainActivity,"初始化失败",Toast.LENGTH_SHORT).show()
            }
        }
        val testerInfo = ITesterInfo
            .Builder()
            .iTesterId("7878121")  //三方业务系统的被测人用户id
            .iTesterPhone("13511111111")
            .iTesterName("张三")
            .iTesterGender("男")
            .iTesterBirthday("1990-01-01")
            .iTesterHeight(180)   //被测人身高，传值为int类型，单位为cm
            .iTesterWeight(120)    //被测人体重，传值为int类型，单位为kg
            .iTesterArea("浙江省杭州市西湖区")    //所在地区 传值为省市区
            .iTesterBirthdayDisplay(true)
            .iTesterAreaDisplay(true)
            .iTesterPhoneDisplay(false)
            .iTesterNameDisplay(false)
            .iTesterHeightDisplay(true)
            .iTesterWeightDisplay(true)
            .build()
        val targetDeviceSn = "BAAA000006"
        findViewById<TextView>(R.id.deviceSnText).text = String.format(Locale.getDefault(),"设备sn：%s",targetDeviceSn)
        findViewById<View>(R.id.openDeteV2Btn).setOnClickListener {
            val isSuccess = DetectionManager.startDetectV2(this,null,testerInfo){
                Toast.makeText(this@MainActivity,it,Toast.LENGTH_SHORT).show()
            }
            if(!isSuccess){
                Toast.makeText(this@MainActivity,"初始化失败",Toast.LENGTH_SHORT).show()
            }
        }
        findViewById<View>(R.id.openDeteV2DeviceBtn).setOnClickListener {
            val isSuccess = DetectionManager.startDetectV2(this,targetDeviceSn,testerInfo){
                Toast.makeText(this@MainActivity,it,Toast.LENGTH_SHORT).show()
            }
            if(!isSuccess){
                Toast.makeText(this@MainActivity,"初始化失败",Toast.LENGTH_SHORT).show()
            }
        }
        findViewById<View>(R.id.openNetworkBtn).setOnClickListener {
            DetectionManager.startDistributionNetwork(this,null,true)
        }
        findViewById<View>(R.id.openNetworkDeviceBtn).setOnClickListener {
            DetectionManager.startDistributionNetwork(this,targetDeviceSn,true)
        }
        findViewById<View>(R.id.getDeviceStatusBtn).setOnClickListener {
            DetectionManager.getDeviceStatus(this,targetDeviceSn,true){status->
                val text = when(status){
                    DetectionManager.DEVICE_STATUS_OFFLINE->{
                        "离线"
                    }
                    DetectionManager.DEVICE_STATUS_ONLINE->{
                        "在线"
                    }
                    DetectionManager.DEVICE_STATUS_UNACTIVED->{
                        "未激活"
                    }
                    else->{
                        "获取失败"
                    }
                }
                Toast.makeText(this@MainActivity,"设备状态：$text",Toast.LENGTH_SHORT).show()
            }
        }
    }

}